{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-form">
    <!-- 基础上传 -->
    <div class="layui-card ns-card-common ns-card-brief">
        <div class="layui-card-header">
            <span class="ns-card-title">结算周期设置</span>
        </div>
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label">结算周期类型：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="radio" name="period_type" value="1" lay-filter="period_type" title="按天" {$config_info.value.period_type == 1 ? 'checked' : ''} />
                        <input type="radio" name="period_type" value="2" lay-filter="period_type" title="按周" {$config_info.value.period_type == 2 ? 'checked' : ''} />
                        <input type="radio" name="period_type" value="3" lay-filter="period_type" title="按月" {$config_info.value.period_type == 3 ? 'checked' : ''} />
                    </div>
                </div>
                <div class="ns-word-aux">按天是指每天0点开始，按周是指每周一0点开始，按月是指每月一号0点开始</div>
            </div>
        </div>
    </div>

    <div class="layui-card ns-card-common ns-card-brief">
        <div class="layui-card-header">
            <span class="ns-card-title">提现设置</span>
        </div>
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label">最低提现金额：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="number" name="min_withdraw" lay-verify="required|flo" value="{$config_info.value.min_withdraw}" autocomplete="off" class="layui-input ns-len-small">
                    </div>
                    <div class="layui-form-mid">元</div>
                </div>
                <div class="ns-word-aux">最低提现金额，对手动申请提现有效</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">最高提现金额：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="number" name="max_withdraw" lay-verify="required|flo|check_num" value="{$config_info.value.max_withdraw}" autocomplete="off" class="layui-input ns-len-small">
                    </div>
                    <div class="layui-form-mid">元</div>
                </div>
                <div class="ns-word-aux">最高提现金额，对手动申请提现有效</div>
            </div>
        </div>
    </div>

    <div class="layui-card ns-card-common ns-card-brief">
        <div class="layui-card-header">
            <span class="ns-card-title">体验入驻设置</span>
        </div>
        <div class="layui-card-body">

            <div class="layui-form-item">
                <label class="layui-form-label">快速入驻：</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="id_experience" value="1" lay-skin="switch" {if condition="$config_info.value.id_experience == 1"}checked{/if} >
                </div>
                <div class="ns-word-aux">开启后，入驻界面显示<span style="color: #4685fd;">快速开店</span>选项</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">体验入驻时长：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <input type="number" name="expire_time"  value="{$config_info.value.expire_time}" min="0" autocomplete="off" class="layui-input ns-len-small">
                    </div>
                    <div class="layui-form-mid">天</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">体验开店套餐：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline">
                        <select name="group_id">
                            <option value="">请选择权限组</option>
                            {foreach $group_list as $group_list_k => $group_list_v}
                            <option value="{$group_list_v.group_id}" {if $group_list_v.group_id==$config_info.value.group_id}selected{/if}>{$group_list_v.group_name} </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

	<div class="ns-single-filter-box">
		<div class="ns-form-row">
			<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		</div>
	</div>
</div>
{/block}
{block name="script"}
<script>
    layui.use(['form'], function() {
        var form = layui.form,
            repeat_flag = false; //防重复标识


        form.render();

        form.verify({
            rate: function(value){
                if(value > 100 || value < 0 || value%1 != 0){
                    return '请填写0-100的整数';
                }
            },
			flo: function (value) {
				console.log(1);
				if (value == '') {
					return;
				}
				var reg = /^(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/;
				if (!reg.test(value)) {
					return '价格不能小于0，可保留两位小数！'
				}
			},
            check_num:function(value){
                if(parseFloat($("input[name='min_withdraw']").val()) > parseFloat(value)){
                    return '最小提现金额不能大于最大提现金额！';
                }
            }
        });

        form.on('submit(save)', function(data) {
            if (repeat_flag) return;
            repeat_flag = true;

            field = data.field;
            if(field.expire_time != ''){
                if(field.id_experience == 1){
                    if(field.group_id == 0){
                        layer.msg('请选择体验开店套餐');
                        repeat_flag = false;
                        return;
                    }
                }
            }
            $.ajax({
                type: 'POST',
                dataType: 'JSON',
                url: ns.url("admin/shopaccount/withdrawconfig"),
                data: {
					'config_json': JSON.stringify(data.field)
				},
                success: function(res) {
                    layer.msg(res.message);
					repeat_flag = false;
                    if (res.code == 0) {
                        location.reload();
                    }
                }
            });
        });
    });
</script>
{/block}